"""
get请求的quote方法
"""

import urllib.request
import urllib.parse

url = "https://www.baidu.com/s?wd="

# 将周杰伦三个汉字变成Unicode编码格式
# 我们需要依赖urllib.parse
name = urllib.parse.quote("周杰伦")
print(name)

url = url + name
print(url)

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.50"
}

# 请求对象的定制
request = urllib.request.Request(url=url, headers=headers)

# 模拟游览器向服务器发送请求
response = urllib.request.urlopen(request)

# 获取相应的内容
content = response.read()

# 打印数据
print(content.decode("utf-8"))
